<template>
    <div class="app-container content-wrapper">
        <div class="filter-container">
            <el-form :model="listQuery" :inline="true" ref="filterForm" style="display: inline-block">
                <el-form-item prop="carFullNum" class="filter-item">
                    <el-input v-model="listQuery.carFullNum" placeholder="车牌号" style="width: 200px;"></el-input>
                </el-form-item>

                <el-button class="filter-item" type="primary" icon="search" @click="handleFilter">搜索</el-button>
                <el-button class="filter-item" type="primary" icon="mars-reset" @click="handleResetFilter">重置</el-button>

            </el-form>
        </div>

        <el-table :data="list" v-loading="listLoading" element-loading-text="给我一点时间" border fit highlight-current-row style="width: 100%">

            <el-table-column label="ID" width="65" align="center">
                <template slot-scope="scope"> {{scope.row.id}} </template>
            </el-table-column>

            <el-table-column label="车牌号" align="center">
                <template slot-scope="scope"> {{scope.row.carArea}}{{scope.row.carCity}}&nbsp;●&nbsp;{{scope.row.carNum}} </template>
            </el-table-column>

            <el-table-column label="车名称" align="center">
                <template slot-scope="scope"> {{scope.row.carName}} </template>
            </el-table-column>

            <el-table-column label="最新更新时间" align="center">
                <template slot-scope="scope"> {{scope.row.checkTime | parseTime('{y}-{m}-{d} {h}:{i}')}} </template>
            </el-table-column>

            <el-table-column label="检查数量" align="center">
                <template slot-scope="scope"> {{scope.row.countCheck}} </template>
            </el-table-column>

            <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                    <el-button size="small" type="primary" icon="edit" @click="handleDetail(scope.row)">详情</el-button>
                </template>
            </el-table-column>

        </el-table>

        <div v-show="!listLoading" class="pagination-container">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="listQuery.page"
                    :page-sizes="[10, 20, 30, 50]"
                    :page-size="listQuery.rows"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </div>


    </div>
</template>

<script>
    import fetch from '@/utils/fetch'
    import { created, deleted, updated, fetchObject, fetchList, listByCarCheck } from '@/api/tukuan/manager'

    const sortOptions = [{label: '按ID升序', key: 'id asc'}, {label: '按ID降序', key: 'id desc'}]

    const carAreaOptions = [
        {label: '粤', key: '粤'},
        {label: '京', key: '京'},
        {label: '辽', key: '辽'}
    ]
    const carCityOptions = [
        {label: 'A', key: 'A'},
        {label: 'B', key: 'B'},
        {label: 'C', key: 'C'},
        {label: 'D', key: 'D'},
        {label: 'E', key: 'E'},
        {label: 'F', key: 'F'},
        {label: 'G', key: 'G'},
        {label: 'H', key: 'H'},
        {label: 'I', key: 'I'},
        {label: 'J', key: 'J'},
        {label: 'K', key: 'K'},
        {label: 'L', key: 'L'},
        {label: 'M', key: 'M'},
        {label: 'N', key: 'N'}
    ]

    export default {
        name: 'app',
        data() {
            return {
                list: null,
                total: null,
                listLoading: true,
                listQuery: {
                    page: 1,
                    rows: 10,
                    carNum: undefined,
                    carName: undefined,
                    orderBy: 'check_time desc'
                },
                sortOptions,
                carAreaOptions,
                carCityOptions,
                dialogFormVisible: false,
                dialogStatus: '',
                textMap: {
                    update: '编辑',
                    create: '创建'
                },
                form: {
                    carArea: '',
                    carCity: '',
                    carNum: '',
                    carName: '',
                    carDriverPic: '',
                    remarks: ''
                },
                rules: {
                    name: [
                        { required: true, message: '请输入应用名称', trigger: 'blur' }
                    ],
                    code: [
                        { required: true, message: '请输入唯一表示', trigger: 'blur' }
                    ]
                }

            }
        },
        created() {
            this.getList()
        },
        filters: {
            statusFilter(status) {
                const statusArray = ['正常', '锁定']
                return statusArray[status?--status:'']
            },
            statusTagFilter(status) {
                const statusArray = ['success', 'danger']
                return statusArray[status?--status:'']
            }
        },
        methods: {
            handleDetail(row) {
                this.$router.push({'path': `/car/check-detail/${row.id}/${row.carFullNum}`})
            },
            getList() {
                this.listLoading = true
                listByCarCheck(this.listQuery).then(response => {
                    this.list = response.data.list
                    this.total = response.data.total
                    this.listLoading = false
                }).catch((error)=>{
                    console.log(error)
                    this.listLoading = false
                })
            },
            handleSizeChange(val) {
                this.listQuery.rows = val
                this.getList()
            },
            handleCurrentChange(val) {
                this.listQuery.page = val
                this.getList()
            },
            handleCloseDialog() {
                this.resetForm()
            },
            handleFilter() {
                this.listQuery.page = 1
                this.getList()
            },
            handleResetFilter() {
                this.$refs.filterForm.resetFields()
                this.getList()
            }
        }
    }
</script>

<!-- 局部样式 -->
<style rel="stylesheet/scss" lang="scss" scoped>

</style>